package cn.rkylin.oms.item.adapter;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import cn.rkylin.apollo.common.util.BeanUtils;
import cn.rkylin.oms.common.base.AbstractAdapterFactory;
import cn.rkylin.oms.item.controller.ItemController;
import cn.rkylin.oms.system.shop.vo.ShopVO;

/**
 * 商品适配器工厂
 * 
 * @author jipengcheng
 * @version 1.0
 * @created 2017.02.13
 */
public class ItemAdapterFactory extends AbstractAdapterFactory {
    private static final Log logger = LogFactory.getLog(ItemAdapterFactory.class);

	/**
	 * 构造函数
	 */
	private ItemAdapterFactory() {

	}

	/**
	 * 判断shopType创建具体的adapter
	 * 
	 * @param shopId
	 * @throws Exception
	 */
	public static ItemAdapter getItemAdapter(String shopId) throws Exception {
		ItemAdapter itemAdapter = null;
		ShopVO shopVO = getShop(shopId);
		if (shopVO == null) {
			return itemAdapter;
		}
		String shopType = shopVO.getShopType();

		if (shopVO != null && shopType.equals("淘宝")) {
			itemAdapter = BeanUtils.getBean("taoBaoItemAdapter");
			TaoBaoItemVisitor taoBaoItemVisitor = BeanUtils.getBean("taoBaoItemVisitor");
			taoBaoItemVisitor.setShopVO(shopVO);
			itemAdapter.setItemVisitor(taoBaoItemVisitor);		
		} else if (shopVO != null && ("小V铺").equals(shopType)) {
			itemAdapter = BeanUtils.getBean("xvpItemAdapter");
			XvpItemVisitor xvpItemVisitor = BeanUtils.getBean("xvpItemVisitor");
			xvpItemVisitor.setShopVO(shopVO);
			itemAdapter.setItemVisitor(xvpItemVisitor);
		} else if (shopVO != null && ("唯品会直发").equals(shopType)) {
			itemAdapter = BeanUtils.getBean("vipItemAdapter");
			VipItemVisitor vipItemVisitor = BeanUtils.getBean("vipItemVisitor");
			vipItemVisitor.setShopVO(shopVO);
			itemAdapter.setItemVisitor(vipItemVisitor);
		}
		return itemAdapter;
	}

}